package 字符串与String的相互转换;

/**
 * @author feng
 * @Date 2022/1/2 8:45
 * 模拟一个trim功能一致的方法。去除字符串两端的空白
 */
public class Test4 {
    public static void main(String[] args) {
        String s = "     a       bc    ";
        String s1 = myTrim(s);
        System.out.println(s1);
    }

    private static String myTrim(String s) {
        int begin = 0;
        int end = s.length() - 1;
        while (begin <= end && s.charAt(begin) == ' ') {
            begin++;
        }
        while (begin <= end && s.charAt(end) == ' ') {
            end--;
        }
        return s.substring(begin, end+1);

    }
}
